var APPCom = (function () {
    var APPCommon = {
        iphoneSchema: 'regal://',
        iphoneDownUrl: 'https://itunes.apple.com/cn/app/id1168383375',
        androidSchema: 'regal://haibei.app/openRegel',
        androidDownUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.easysoft.shell',
        openApp: function () {
            var this_ = APPCommon;
            //微信
            if (this_.isWeixin()) {
                if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                    window.location.href = this_.iphoneDownUrl;
                } else if (navigator.userAgent.match(/android/i)) {
                    window.location.href = this_.androidDownUrl;
                }
            } else { //非微信浏览器
                if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                    var loadDateTime = new Date();
                    window.setTimeout(function () {
                        var timeOutDateTime = new Date();
                        console.log(timeOutDateTime - loadDateTime);
                        if (timeOutDateTime - loadDateTime < 500) {
                            window.location.href = this_.iphoneDownUrl; //ios下载地址
                        } else {
                            //window.close();
                        }
                    }, 60);
                    window.location.href = this_.iphoneSchema;
                } else if (navigator.userAgent.match(/android/i)) {
                    try {
                        console.log(0)
                        var loadDateTime = new Date();
                        setTimeout(function () {
                            var timeOutDateTime = new Date();
                            if (timeOutDateTime - loadDateTime < 500) {
                                console.log(11);
                                window.location.href = this_.androidDownUrl; //android下载地址
                            } else {
                                //	window.close();
                            }
                        }, 25);
                        window.location.href = this_.androidSchema;
                    } catch (e) {
                        console.log(e)
                    }
                }
            }
        },
        isWeixin: function () { //判断是否是微信
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true;
            } else {
                return false;
            }
        }

    };
    return {
        init: APPCommon.openApp,
    }
})();
export default APPCom;